{extend name="common/base"/}
<!-- 主体 -->
{block name="body"}
<form class="layui-form p-4">
    {if condition="$id eq 0"}
    <h3 class="pb-3">新增客服</h3>
    <table class="layui-table layui-table-form">
        <tr>
            <td class="layui-td-gray-2">客服名称<font>*</font></td>
            <td colspan="2">
                <input type="text" name="name"  lay-verify="required" placeholder="请输入客服名称"  class="layui-input" value="" >
            </td>
        </tr>
        <tr>
            <td class="layui-td-gray-2">二维码<font>*</font></td>
            <td colspan="2">
                <div class="layui-upload">
                    <button type="button" class="layui-btn layui-btn-normal layui-btn-sm"
                            id="uploadBtn">上传缩略图（尺寸：240x136）</button>
                    <div class="layui-upload-list" id="demo1" style="width: 120px; height:66px; overflow: hidden;">
                        <img src="" style="max-width: 100%; height:66px;" />
                        <input type="hidden" name="kefu_img" value="">
                    </div>
                </div>
            </td>
        </tr>

        <tr>
            <td class="layui-td-gray-2">排序</td>
            <td>
                <input type="text" name="sorts" lay-verify="required|number" placeholder="请输入排序"  class="layui-input">
            </td>
        </tr>
        <tr>
            <td class="layui-td-gray-2">状态</td>
            <td colspan="2">
                <input type="radio" name="status" value="1" title="正常" checked>
                <input type="radio" name="status" value="0" title="禁用" >

            </td>
        </tr>
    </table>
    {else/}
    <h3 class="pb-3">修改客服</h3>
    <table class="layui-table layui-table-form">
        <tr>
            <td class="layui-td-gray-2">客服名称<font>*</font></td>
            <td colspan="2">
                <input type="text" name="name" value="{$data.name}" lay-verify="required" placeholder="请输入广告名称"  class="layui-input" value="" >
            </td>

        </tr>
        <tr>
            <td class="layui-td-gray-2">二维码<font>*</font></td>
            <td colspan="2">
                <div class="layui-upload">
                    <button type="button" class="layui-btn layui-btn-normal layui-btn-sm"
                            id="uploadBtn">上传缩略图（尺寸：240x136）</button>
                    <div class="layui-upload-list" id="demo1" style="width: 120px; height:66px; overflow: hidden;">
                        <img src="{$data.kefu_img}" style="max-width: 100%; height:66px;" />
                        <input type="hidden" name="kefu_img" value="{$data.kefu_img}">
                    </div>
                </div>
            </td>
        </tr>

        <tr>
            <td class="layui-td-gray-2">排序</td>
            <td>
                <input type="text" name="sorts" placeholder="请输入排序"  class="layui-input"
                       {notempty name="$data.sorts" }value="{$data.sorts}" {/notempty}>
            </td>
        </tr>
        <tr>
            <td class="layui-td-gray-2">状态</td>
            <td colspan="2">
                <input type="radio" name="status" value="1" title="正常" {eq name="$data.status" value="1" }checked{/eq}>
                <input type="radio" name="status" value="0" title="禁用" {eq name="$data.status" value="0"}checked{/eq}>

            </td>
        </tr>
    </table>
    {/if}

    <div class="py-3">
        <input type="hidden" name="id" value="{$id}" />
        <button class="layui-btn layui-btn-normal" lay-submit="" lay-filter="webform">立即提交</button>
        <button type="reset" class="layui-btn layui-btn-primary">重置</button>
    </div>
</form>
{/block}
<!-- /主体 -->

<!-- 脚本 -->
{block name="script"}
<script>
    const moduleInit = ['tool'];
    function gouguInit() {
        var form = layui.form,tool=layui.tool,upload = layui.upload;

        //封面上传
        var uploadInst = upload.render({
            elem: '#uploadBtn'
            , url: '/webadmin/api/upload'
            , done: function (e) {
                //如果上传失败
                if (e.code == 1) {
                    return layer.msg('上传失败');
                }
                //上传成功
                $('#demo1 input').attr('value', e.data.filepath);
                $('#demo1 img').attr('src', e.data.filepath);
            }
        });
        //监听提交
        form.on('submit(webform)', function (data) {
            let callback = function (e) {
                layer.msg(e.msg);
                if (e.code == 0) {
                    setTimeout(function () {
                        parent.location.reload();
                    }, 1000);
                }
            }
            tool.post("/webadmin/kefu/add", data.field, callback);
            return false;
        });
    }
</script>
{/block}
<!-- /脚本 -->
